<template>
    <div class="components-container">
     
        <div style="height:56px">
            <ul class="toolList">
                <li><el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading">刷新</el-button></li>
                <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
                  <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
                </li>
            </ul>
        </div>
        <dataTable :headList="headList" :dataList="dataList" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>
      
       <arehousingManageMain ref="dialog" @refreshData="getData"></arehousingManageMain>
       <printmodal ref="printPdf"></printmodal>
    </div>
</template>

<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.el-button + .el-button {
  margin-left: 0;
}
.btnCenter {
  text-align: center;
}
</style>
<script>
import sweetModal from "@/components/sweetModal";
import dataTable from "@/components/Table/DataTable";
import arehousingManageMain from "./arehousingManageMain";
import arehousingManageMainWck from "@/views/idv/330782X1F1/warehouse/arehousingManageMain";
import apiBase from "@/api/apiBase.js";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import { manage } from "@/mixins/managePage.js";
import { DATESELECTMODE } from "@/const/const.js";
import { ORDER } from "@/const/orderConst.js";
import { PRINT } from "@/components/Pdf/PDF.js";
import printmodal from "@/components/Pdf/Print";
const orgcode = typeof getOrgCode === "function" ? getOrgCode() : '';


const Warehousing = "入库";
const changes = "修改";
const deletes = "删除";
const submits = "提交";
const copy = "打印";
const INFO = "详情";
const QXTJ = "取消提交";

const WJZ = "A";
const YJZ = "B";
const YZF = "C";
const YGZ = "D";
const HZ = "E";

export default {
  name: "arehousingManage",
  mixins: [manage],
  data() {
    return {
      DateSelectMode: DATESELECTMODE,
      //查询条件
      selectData: {},
      selectDataExtend: {
        regDateValue: null
      },
      //收费信息
      chdData: {},
      //付款方式
      payment: [],
      CHDCODNAME: null,
      chlList: []
    };
  },
  methods: {
    //获取收费信息
    getData() {
      // let selectData = JSON.parse(JSON.stringify(this.selectData));
      // if (!this.selectData.RegbussnumLike) {
      //   selectData.RegbussnumLike = null;
      // }
      let data = {
        PageIndex: this.pageOrder.currentPage,
        PageSize: this.pageOrder.pageSize,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        // Data: selectData
      };
      apiBase.DoService(data, apiBase.getApiAdress().Depot.QueryDpi, res => {
        this.dataList = res.data.content.OutData;
        this.pageOrder.totalNum = res.data.content.RecordCount;
        // this.dataList.forEach(data => {
        //   data.REGDATE = data.REGDATE.substring(0, 16);
        // });
        // console.log(res);
      });
    },
    //功能操作
    operate(order){
      console.log(order);
      this.order = order;
      switch (this.order) {
        case Warehousing:
          this.$refs.dialog.open(this.order);
          break;
        case '无仓库入库':
          this.$refs.dialog.open(this.order);
          break;
        case changes:
          this.$refs.dialog.open(this.order,this.currentRow.DPIID);
          break;
        case INFO:
          this.$refs.dialog.open(this.order,this.currentRow.DPIID);
          break;
        case submits:
          this.submission();
          break;
        case deletes:
          this.deletes();
          break;
        case copy:
          this.$refs.printPdf.open("入库",this.currentRow.DPIID);
          // alert('你好啊!');
          break;
        case QXTJ:
          this.qxtj();
          break;
        default:
      }
    },
    //取消提交
    qxtj(){
      this.$confirm("确认是否取消提交?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
          .then(callback => {
              let data = {
                DPIID: this.currentRow.DPIID
              };
              apiBase.DoService(
                data,
                apiBase.getApiAdress().Depot.CancelSubmitDpi,
                res => {
                  this.getData();
                }
              );
            })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消"
            });
          });
    },
    //入库删除
    deletes(){
      this.$confirm("确认是否删除该数据?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
          .then(callback => {
              let data = {
                DPIID: this.currentRow.DPIID
              };
              apiBase.DoService(
                data,
                apiBase.getApiAdress().Depot.DeleteDpi,
                res => {
                  this.getData();
                }
              );
            })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消"
            });
          });
    },
    //入库提交
    submission(){
      this.$confirm("确认是否提交该数据?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
          .then(callback => {
               let data = {
                  DPIID: this.currentRow.DPIID
                }
                apiBase.DoService(
                  data,
                  apiBase.getApiAdress().Depot.SubmitDpi,
                  res => {
                    this.$message({
                      type: "success",
                      message: "提交成功!"
                    });
                    this.getData();
                  }
                )
            })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消"
            });
      });
    },
    //获取表头
    getheaderlist(){
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Column.GetArehousingColumns,
        res => {
          console.log(res);
          this.headList = res.data.content;
        }
      )
    },
    //取消
    cancel(){
        this.$refs.dialog.close();
    },
    //查询条件重置
    btnRepeat() {
      this.selectData = {};
      this.getData();
    },
    dataRepeat() {
      this.chdData = {};
    },
    //按钮显隐
    btnShow(btn) {
       let status = '';
      if(this.currentRow){
        status = this.currentRow.DPIDATE;
      }
      if(btn === Warehousing) return true;
      if(btn === '无仓库入库') return true;
      if(!this.currentRow) return false;
      if(btn === copy) return true;  
      if(btn === QXTJ && status) return true; 
      if(btn === submits && !this.currentRow.DPIDATE) return true;
      if(btn === deletes && !this.currentRow.DPIDATE) return true;
      if(btn === changes && !this.currentRow.DPIDATE) return true;
    },
   
  },
  components: {
    sweetModal,
    dataTable,
    printmodal,
    arehousingManageMain:(()=>{
      switch (orgcode) {
        case '330782X1F1':
          return arehousingManageMainWck
          break;
        default:
          return arehousingManageMain
          break;
      }
    })()
  },
  activated() {
    this.getData();
  },
  mounted() {
  },
  created() {
    this.getheaderlist();
  },
  watch: {
    "selectDataExtend.regDateValue": function(val) {
      this.selectData.RegdateGreater = null;
      this.selectData.RegDateOrChdDate = null;
      switch (val) {
        case DATESELECTMODE.now:
          this.selectData.RegDateOrChdDate = formatDate(new Date(), "yyyyMMdd");
          break;
        case DATESELECTMODE.future:
          this.selectData.RegdateGreater = formatDate(new Date(), "yyyyMMdd");
          break;
        default:
          break;
      }
    }
  }
};
</script>

